package services

import (
	"encoding/json"
	"errors"
	"fmt"
	"strconv"
	"strings"
	"time"

	"github.com/beego/beego/v2/client/orm"
	"weiboxs.com/new_h_glasses/models"
	"weiboxs.com/new_h_glasses/utils"
)

type ErpEntryFormData struct {
	Id           int64
	Number       string
	Remarks      string
	Suppliers    int64
	Postage      float64
	CreatedAt    int64
	UpdatedAt    int64
	CreatedBy    string
	UpdatedBy    string
	PayMethod    int
	DeliveryMode int

	Rowsnum      string
	Rowsdata     []map[string]interface{}
	DepartmentId int64
}

func CreateEntryNumber() string {
	stat := utils.GetDateParse(time.Now().Format("2006-01-02"))
	end := stat + 86400
	return fmt.Sprintf("%s%06d", time.Now().Format("20060102150405"), models.QueryEntryTimeSoltSeterCount(stat, end, )+1)
}

type TmpSaveErpEntryData struct {
	DepId       int64
	GoodsId     int64
	EntryId     int64
	MiddleId    int64
	PurchaseNum int64
	Attribute   string
	Data        string
}

//保存明细数据2020-05
func (s *ErpEntryFormData) SaveErpEntryData(value *TmpSaveErpEntryData, u *models.BackendUser) (int64, error) {

	//获取商品信息
	goods, err := models.GetErpProductsById(value.GoodsId, u)
	if err != nil {
		return 0, err
	}
	//写入中间表
	to,_ := orm.NewOrm().Begin()
	middle := new(models.ErpEntryMiddle)
	middle.Products = goods
	middle.EntryId = value.EntryId
	middle.Attribute = value.Attribute
	middle.PurchaseNum = value.PurchaseNum
	var middle_id int64
	if value.MiddleId > 0 { //已存在
		middle_id = value.MiddleId
		//清除已有数据
		if _, err := to.Raw("DELETE FROM "+models.ErpEntryDataTableName()+" WHERE middle_id=?", middle_id).Exec(); err != nil { //删除明细表
			utils.LogInfo(err)
		}
		middle.Id = middle_id
		if _, err := to.Update(middle, "PurchaseNum"); err != nil { //更新数量
			utils.LogInfo(err)
		}
	} else {
		middle_id, err = to.Insert(middle)
		if err != nil {
			return 0, err
		}
	}
	//写入明细表
	entry_datas := make([]*models.ErpEntryData, 0)
	if len(value.Data) > 0 {
		if err := json.Unmarshal([]byte(value.Data), &entry_datas); err != nil {
			to.Rollback()
			return 0, err
		}
	}
	if len(entry_datas) <= 0 {
		to.Rollback()
		return 0, errors.New("没有可用数据")
	}

	for key, _ := range entry_datas {
		ed := entry_datas[key]
		ed.Entry = &models.ErpEntry{Id: value.EntryId}
		ed.Products = goods
		ed.MiddleId = middle_id
		if goods.TypeId == 40 {
			ed.Addlight = ed.Astigmatism
			ed.Astigmatism = ""
		}

		//写入SND数据
		snd := new(models.ErpProductsSnd) //创建SND
		if goods.TypeId != 50 && goods.TypeId != 60 { //护理产品及辅料其它不需要SND
			snd.Products = goods
			snd.Id = ed.SndId
			snd.Sph = ed.Diopter
			snd.Cyl = ed.Astigmatism
			snd.Add = ed.Addlight
			snd.Color = strings.ToUpper(ed.ColourNumber)
			snd.Model = strings.ToUpper(ed.ModelNumber)
			snd.Size = strings.ToUpper(ed.Size)
			snd.Genre = strings.ToUpper(ed.Genre)
			snd.FilmColor = strings.ToUpper(ed.FilmColor)
			snd.FunctionInfo = strings.ToUpper(ed.FunctionInfo)
			if err := models.ErpProductsSndSave(to, snd); err != nil {
				to.Rollback()
				return 0, err
			}
			if snd.Id == 0 {
				to.Rollback()
				return 0, errors.New("Snd不存在")
			}
		}
		ed.Snd = snd
		entry_datas[key] = ed
	}
	if _, err := to.InsertMulti(len(entry_datas), entry_datas); err != nil {
		to.Rollback()
		return 0, err
	}
	to.Commit()
	return middle_id, nil
}

//获取中间数据明细2020-05
func (s *ErpEntryFormData) GetMiddleForEntryData(middle_id int64) []*models.ErpEntryData {
	if middle_id == 0 {
		return nil
	}
	entry_data := make([]*models.ErpEntryData, 0);
	orm.NewOrm().QueryTable(models.ErpEntryDataTableName()).RelatedSel("Snd").Filter("middle_id", middle_id).All(&entry_data)
	return entry_data
}

//删除中间数据2020-05
func (s *ErpEntryFormData) DeleteMiddleData(middle_id int64) error {

	to,_ := orm.NewOrm().Begin()

	middle := &models.ErpEntryMiddle{Id: middle_id}
	if err := to.Read(middle); err != nil {
		return err
	}
	if _, err := to.Delete(middle); err != nil { //删除中间数据
		return err
	}
	if _, err := to.Raw("DELETE FROM "+models.ErpEntryDataTableName()+" WHERE middle_id=?", middle_id).Exec(); err != nil { //删除明细表
		to.Rollback()
		return err
	}
	to.Commit()

	return nil
}

//写入单据信息202005
func (s *ErpEntryFormData) ErpEntryFormInsert(isTemp int) (int64, error) {

	entry := new(models.ErpEntry)
	entry.Auditing = 0
	entry.Money = 0
	entry.ProNumber = 0
	entry.Reconciliation = 2
	entry.DepartmentId = s.DepartmentId
	entry.Postage = s.Postage
	entry.CreatedAt = s.CreatedAt
	entry.UpdatedAt = time.Now().Unix()
	entry.CreatedBy = s.CreatedBy
	entry.UpdatedBy = s.UpdatedBy
	entry.UpdatedAt = s.UpdatedAt
	entry.PayMethod = s.PayMethod
	entry.DeliveryMode = s.DeliveryMode
	entry.IsTemp = isTemp
	entry.Number = s.Number
	entry.Remarks = s.Remarks
	entry.Suppliers = &models.ErpSuppliers{Id: s.Suppliers}

	orm := orm.NewOrm()
	var err error
	//添加主表数据
	_, err = orm.Insert(entry)
	if err != nil {
		return 0, err
	}
	return entry.Id, err
}

//修改数据2020-05
func (s *ErpEntryFormData) ErpEntryFormUpdate() error {

	entry := new(models.ErpEntry)
	entry.Id = s.Id
	entry.UpdatedAt = time.Now().Unix()
	entry.UpdatedBy = s.UpdatedBy
	entry.Number = s.Number
	entry.Remarks = s.Remarks
	entry.Suppliers = &models.ErpSuppliers{Id: s.Suppliers} //增加供应商
	entry.Postage = s.Postage

	to,_ := orm.NewOrm().Begin()

	var err error

	if _, err = to.Update(entry, "updated_at", "updated_by", "number", "remarks", "pro_number", "money", "postage", "suppliers_id"); err != nil {
		to.Rollback()
		return err
	}

	to.Commit()

	return nil
}

//保存数据2020-05
func (s *ErpEntryFormData) SubmitOrder(entry_id, depid int64) error {

	erpentry, _ := models.GetErpEntryById(entry_id)
	if erpentry.Id == 0 || erpentry.DepartmentId != depid {
		return errors.New("找不到数据")
	}
	if erpentry.IsTemp == 0 {
		return errors.New("该单据已提交，无需重复")
	}
	pro_number, acceptance_check, total_money, err := s.getResetEntryNumber(erpentry)
	if err != nil {
		return err
	}
	erpentry.AcceptanceCheck = acceptance_check
	erpentry.ProNumber = pro_number
	erpentry.Money = total_money
	erpentry.IsTemp = 0
	if err := erpentry.ErpEntryEdit("AcceptanceCheck", "ProNumber", "Money", "IsTemp"); err != nil {
		return err
	}
	return nil
}

//重置订单产品数量
func (s *ErpEntryFormData) getResetEntryNumber(erpentry *models.ErpEntry) (int64, int64, float64, error) {
	o := orm.NewOrm()
	//获取
	ertry_data := make([]*models.ErpEntryData, 0)
	if _, err := o.QueryTable(models.ErpEntryDataTableName()).RelatedSel("Products").Filter("entry_id", erpentry.Id).All(&ertry_data); err != nil {
		return 0, 0, 0, err
	}
	if len(ertry_data) <= 0 {
		return 0, 0, 0, errors.New("请选择需要入库的商品")
	}
	var (
		acceptance_check int64   //待验收数量
		pro_number       int64   //产品数量
		total_money      float64 //总金额
	)
	for key, _ := range ertry_data {
		value := ertry_data[key]
		if value.Products.TypeId == 20 || value.Products.TypeId == 50 || value.Products.TypeId == 70 { //需要验收的数据
			acceptance_check += value.Amount
		}
		pro_number += value.Amount     //总产品数量
		total_money += value.SmallPlan //总金额
	}

	return pro_number, acceptance_check, total_money, nil
}

//审核单据202005
func (s *ErpEntryFormData) ErpEntryAuditing(entry *models.ErpEntry) error {
	orms := orm.NewOrm()
	var err error = nil
	pro_number, acceptance_check, _, err := s.getResetEntryNumber(entry)
	if err != nil {
		return err
	}
	entry.AcceptanceCheck = acceptance_check
	entry.ProNumber = pro_number
	_, err = orms.Update(entry, "updated_by", "updated_at", "auditing", "ProNumber", "AcceptanceCheck")
	if err != nil {
		return err
	}
	return err
}

//按类型获取采购数据
func (s *ErpEntryFormData) TakeTypeIdGetEntryData(entry_id int64, typeid int, depid int64) []*models.ErpEntryData {
	data := make([]*models.ErpEntryData, 0)
	o := orm.NewOrm().QueryTable(models.ErpEntryDataTableName()).RelatedSel("Products", "Snd")
	o.Filter("Entry__id", entry_id).Filter("Products__type_id", typeid).Filter("Products__department_id", depid).All(&data)
	return data
}

//按类型获取采购数据
func (s *ErpEntryFormData) TakeTypeIdAcceptData(entry_id int64, typeid int, depid int64) []*models.ErpAcceptanceData {
	data := make([]*models.ErpAcceptanceData, 0)
	o := orm.NewOrm().QueryTable(models.ErpAcceptanceDataTableName()).RelatedSel("Products", "Snd")
	o.Filter("Entry__id", entry_id).Filter("Products__type_id", typeid).Filter("Products__department_id", depid).All(&data)
	return data
}

//按类型获取采购数据同步处理已验收
func (s *ErpEntryFormData) TakeTypeIdGetEntryDataAcceptance(entry_id int64, typeid int, acceptance bool, depid int64) []*models.ErpEntryData {
	data := s.TakeTypeIdGetEntryData(entry_id, typeid, depid)
	if acceptance == true {
		acceptance := s.TakeTypeIdGetAcceptanceDataCount(entry_id)
		targetData := make([]*models.ErpEntryData, 0)
		for k, _ := range data {
			value := data[k]
			ids := strconv.FormatInt(value.Id, 10)
			if _, ok := acceptance[ids]; ok {
				accept_num, _ := strconv.ParseInt(acceptance[ids].(string), 10, 64)
				data[k].Amount -= accept_num
			}
			if data[k].Amount > 0 {
				targetData = append(targetData, data[k])
			}
		}
		data = targetData
	}
	return data
}

//已获取校验数量
func (s *ErpEntryFormData) TakeTypeIdGetAcceptanceDataCount(entry_id int64) map[string]interface{} {
	orm.NewOrm().QueryTable(models.ErpAcceptanceTableName())
	res := make(orm.Params)
	orm.NewOrm().Raw("SELECT SUM(A.acceptance_num) as sum_num, A.entry_data_id FROM "+models.ErpAcceptanceDataTableName()+" A LEFT OUTER JOIN `"+models.ErpAcceptanceTableName()+"` B ON B.`id` = A.`acceptance_id` WHERE B.entry_id=? GROUP BY A.entry_data_id", entry_id).RowsToMap(&res, "entry_data_id", "sum_num")
	return res
}

type TempAcceptanceData struct {
	EntryDataId     string `json:"entry_data_id"`
	GoodsId         string `json:"goods_id"`
	SndId           string `json:"snd_id"`
	Diopter         string `json:"sph"`              //屈光度
	Astigmatism     string `json:"cyl"`              //散光度
	ManufactureDate string `json:"manufacture_date"` //生产日期
	LotNumber       string `json:"lot_number"`       //批号
	ExpiryDate      string `json:"expiry_date"`      //有效日期
	AcceptanceNum   string `json:"accept_num"`       //验收数量
	ShelfLife       string `json:"shelf_life"`       //保质期
}

//保存验收数据
func (s *ErpEntryFormData) SaveAcceptance(accept *models.ErpAcceptance, temp []*TempAcceptanceData) error {
	if len(temp) <= 0 {
		return errors.New("没有可用的数据")
	}
	to,_ := orm.NewOrm().Begin()
	tm := time.Unix(time.Now().Unix(), 0)
	accept.Number = fmt.Sprintf("%s%06d", tm.Format("20060102150405"), accept.Entry.Id)
	if _, err := to.Insert(accept); err != nil { //写入验收主表
		return err
	}
	var data []*models.ErpAcceptanceData
	for k, _ := range temp {
		t := new(models.ErpAcceptanceData)
		v := temp[k]
		t.Acceptance = accept
		goods_id, _ := strconv.ParseInt(v.GoodsId, 10, 64)
		t.Products = &models.ErpProducts{Id: goods_id}
		t.Entry = accept.Entry
		snd_id, _ := strconv.ParseInt(v.SndId, 10, 64)

		t.Snd = &models.ErpProductsSnd{Id: snd_id}
		//t.Diopter = v.Diopter
		//t.Astigmatism = v.Astigmatism
		t.LotNumber = v.LotNumber
		t.ExpiryDate = utils.GetDateParse(v.ExpiryDate)
		t.ShelfLife = v.ShelfLife
		accept_num, _ := strconv.ParseInt(v.AcceptanceNum, 10, 64)
		t.AcceptanceNum = accept_num
		t.ManufactureDate = utils.GetDateParse(v.ManufactureDate)
		entry_data_id, _ := strconv.ParseInt(v.EntryDataId, 10, 64)
		t.EntryDataId = entry_data_id
		accept.AcceptanceNum = accept.AcceptanceNum + accept_num
		data = append(data, t)
	}
	if _, err := to.InsertMulti(len(data), data); err != nil { //写入明细数据
		to.Rollback()
		return err
	}
	//更新验收数量
	if _, err := to.Update(accept, "AcceptanceNum"); err != nil {
		to.Rollback()
		return err
	}
	//更新采购表待验收数量
	_, err := to.QueryTable(models.ErpEntryTableName()).Filter("id", accept.Entry.Id).Update(orm.Params{
		"acceptance_check": orm.ColValue(orm.ColMinus, accept.AcceptanceNum),
	})
	if err != nil {
		to.Rollback()
		return err
	}
	to.Commit()
	return nil
}

/**
* 保存入库
 */
type TempWarehousingData struct {
	EntryDataId     string `json:"id"`
	AcceptId        string `json:"glasses_purchase_goods_detail_id"` //验收ID
	GoodsName       string `json:"goods_name"`
	GoodsId         string `json:"goods_id"`
	SndId           string `json:"snd_id"`
	Diopter         string `json:"sph"`              //屈光度
	Astigmatism     string `json:"cyl"`              //散光度
	AddInfo         string `json:"add_info"`         //下加光
	DateManufacture string `json:"manufacture_date"` //生产日期
	BatchNumbers    string `json:"lot_number"`       //批号
	EffectiveDate   string `json:"expiry_date"`      //有效日期
	ShelfLife       string `json:"shelf_life"`       //保质期
	ModelNumber     string `json:"model"`            //型号
	ColourNumber    string `json:"color"`            //色号
	Size            string `json:"size"`             //尺寸
	FunctionInfo    string `json:"function_info"`    //功效
	FilmColor       string `json:"film_color"`       //膜层颜色
	Genre           string `json:"genre"`            //框形
	AcceptNum       string `json:"accept_num"`       //验收数量
	StorageNum      string `json:"storage_num"`      //入库数量
	PurchaseNum     string `json:"purchase_num"`     //实际数量
}

//采购入库
func (s *ErpEntryFormData) SaveWarehousing(cur *models.BackendUser, entry *models.ErpEntry, temp []*TempWarehousingData) error {
	if len(temp) <= 0 {
		return errors.New("没有可用的数据")
	}
	to,_ := orm.NewOrm().Begin()

	var (
		TotalStorageNum  int64
		TotalPurchaseNum int64
	)
	//流水明细
	flowingData := make([]*models.ErpFlowingData, 0)
	invSer := new(ErpInventoryService)
	checkHas := make(map[string]int)
	for k, _ := range temp {
		v := temp[k]
		inv := new(models.ErpInventory)
		goods_id, _ := strconv.ParseInt(v.GoodsId, 10, 64)
		inv.Products = &models.ErpProducts{Id: goods_id}
		inv.DepartmentId = entry.DepartmentId
		inv.ProductName = utils.ConvertPinyin(v.GoodsName)
		acpt, _ := strconv.ParseInt(v.AcceptId, 10, 64)
		inv.Acceptance = &models.ErpAcceptanceData{Id: acpt}
		snd_id, _ := strconv.ParseInt(v.SndId, 10, 64)
		inv.Snd = &models.ErpProductsSnd{Id: snd_id}
		storage_num, _ := strconv.ParseInt(v.StorageNum, 10, 64)
		inv.Inventory = storage_num
		key := fmt.Sprintf("%d-%d-%d-%d", inv.Products.Id, inv.DepartmentId, inv.Acceptance.Id, inv.Snd.Id)
		if _,ok := checkHas[key];ok{
			continue
		} else {
			checkHas[key] = 1
		}
		if hascode, err := models.CalculateInventoryHascode(inv); err != nil { //值出错整个返回不做处理
			to.Rollback()
			return err
		} else {
			inv.Hascode = hascode
		}
		accept_num, _ := strconv.ParseInt(v.AcceptNum, 10, 64)
		purchase_num, _ := strconv.ParseInt(v.PurchaseNum, 10, 64)
		TotalStorageNum += inv.Inventory //计算总入库量
		//计算订单实际数量，只允许小于或等于
		TotalPurchaseNum += accept_num + purchase_num

		//判断商品是否在盘点中
		if err := StocksCheckIng(inv.Products.Id, cur); err != nil {
			to.Rollback()
			return err
		}

		//开始库存操作
		queryInv := invSer.QueryInventoryOne(0, inv.Hascode)
		var primaryStorageNum int64 //原库存数量
		if queryInv.Id > 0 { //存在则直接增加库存
			primaryStorageNum = queryInv.Inventory
			if err := invSer.UpdateErpInventory(to, queryInv, inv.Inventory); err != nil {
				to.Rollback()
				return err
			}
			inv.Id = queryInv.Id
		} else { //不存在则新增库存记录
			if err := invSer.InsertErpInventory(to, inv); err != nil {
				to.Rollback()
				return err
			}
		}
		if entry_data_id, err := strconv.ParseInt(v.EntryDataId, 10, 64); err != nil {
			to.Rollback()
			return errors.New("明细表数据转换失败")
		} else {
			//更新入库单库存ID
			if _, err := to.Update(&models.ErpEntryData{Id: entry_data_id, InventoryId: inv.Id}, "InventoryId"); err != nil {
				to.Rollback()
				return err
			}
		}
		//设置流水明细
		flowing := new(models.ErpFlowingData)
		flowing.Typeid = 1 //采购入库
		flowing.DepartmentId = inv.DepartmentId
		flowing.Products = inv.Products
		flowing.Acceptance = inv.Acceptance
		flowing.InventoryId = inv.Id
		flowing.PrimaryStorageNum = primaryStorageNum
		flowing.StorageNum = inv.Inventory
		flowing.Snd = inv.Snd
		flowing.PurchaseUpNo = entry.Number
		flowingData = append(flowingData, flowing)

		//更新入库实际数量
		if inv.Acceptance.Id == 0 { //更新入库订单
			if _, err := to.QueryTable(models.ErpEntryDataTableName()).Filter("id", v.EntryDataId).Update(orm.Params{
				"storage_num": inv.Inventory,
			}); err != nil {
				to.Rollback()
				return err
			}
		} else { //更新验收数量
			if _, err := to.QueryTable(models.ErpAcceptanceDataTableName()).Filter("id", v.AcceptId).Update(orm.Params{
				"storage_num": inv.Inventory,
			}); err != nil {
				to.Rollback()
				return err
			}
		}
	}
	//判断订单数是否小于或等于入库数
	if TotalStorageNum > TotalPurchaseNum {
		to.Rollback()
		return errors.New("入库数量不正确")
	}

	//入库记录
	flSer := new(ErpFlowingService)
	flow := new(models.ErpFlowing)
	flow.DepartmentId = entry.DepartmentId
	flow.Typeid = 1 //采购入库
	flow.Entry = entry
	flow.FlowingDate = time.Now().Unix()
	flow.FlowingNum = TotalPurchaseNum
	flow.FlowingUser = cur.RealName
	if err := flSer.SaveErpFlowing(to, flow); err != nil {
		to.Rollback()
		return err
	}
	//写入流水明细
	if err := flSer.SaveErpFlowingData(to, flow, flowingData); err != nil {
		to.Rollback()
		return err
	}
	//判断如果总入库数与订单数量相等表示改订单也全部入库,将订单状态更改为已入库
	entry.StorageNum += TotalStorageNum
	if entry.ProNumber == entry.StorageNum {
		entry.Auditing = 4
		if _, err := to.Update(entry, "Auditing", "StorageNum"); err != nil {
			to.Rollback()
			return err
		}
	} else { //不等则更新入库数量
		if _, err := to.Update(entry, "StorageNum"); err != nil {
			to.Rollback()
			return err
		}
	}
	to.Commit()
	return nil
}

//查看数据202005
func ErpEntryView(id, depid int64) (*models.ErpEntry, error) {
	var err error
	orm := orm.NewOrm()
	//获取主表信息
	entry := new(models.ErpEntry)
	err = orm.QueryTable(models.ErpEntryTableName()).RelatedSel("Suppliers").Filter("department_id", depid).Filter("id", id).One(entry)
	if err != nil {
		return nil, err
	}
	return entry, nil
}

//删除指定出入库记录
func ErpEntryDelete(id int64) error {
	to,_ := orm.NewOrm().Begin()
	entry := &models.ErpEntry{Id: id}

	if err := to.Read(entry); err != nil { //查询是否存在记录信息
		to.Rollback()
		return err
	}

	if entry.Auditing != 2 && entry.Auditing != 0 {
		return errors.New("已通过审核的数据不允许删除")
	}

	//删除副表内容
	if _, err := to.QueryTable(models.ErpEntryDataTableName()).Filter("entry_id", id).Delete(); err != nil {
		to.Rollback()
		return err
	}

	if _, err := to.Delete(entry); err != nil {
		to.Rollback()
		return err
	}

	to.Commit()

	return nil
}

//确认对帐
func ErpEntryReconciliation(id int64, user models.BackendUser) error {
	if id == 0 {
		return errors.New("参数错误")
	}
	model := models.ErpEntry{}
	model.Id = id
	model.Reconciliation = 1
	model.ReconciliationUser = user.RealName
	model.ReconciliationDate = utils.GetDate(time.Now().Unix())
	if _, err := orm.NewOrm().Update(&model, "reconciliation", "reconciliation_user", "reconciliation_date"); err != nil {
		return err
	}
	return nil
}

//删除临时数据
func ErpEntryDeleteTemp(depid int64) error {
	one := new(models.ErpEntry)
	to,_ := orm.NewOrm().Begin()
	to.QueryTable(models.ErpEntryTableName()).Filter("is_temp", 1).Filter("department_id", depid).One(one)
	if one.Id > 0 {
		if _, err := to.Raw("DELETE FROM "+models.ErpEntryDataTableName()+" WHERE entry_id=?", one.Id).Exec(); err != nil { //删除数据表
			to.Rollback()
			return err
		}
		if _, err := to.Raw("DELETE FROM "+models.ErpEntryMiddleTableName()+" WHERE entry_id=?", one.Id).Exec(); err != nil { //删除中间表
			to.Rollback()
			return err
		}
		if _, err := to.Delete(one); err != nil {
			to.Rollback()
			return err
		}
		to.Commit()
		return nil
	}
	return nil
}

//按库存生成采购单
type InventoryCreateEntry struct {
	InvIds   int64 `json:"inv_id"`
	purchase int64 `json:"purchase"`
}

func SetInventoryCreateEntry(u *models.BackendUser, product_id, suppliers int64, invlist string) error {
	if product_id == 0 || suppliers == 0 {
		return errors.New("参数错误")
	}
	list := make([]*InventoryCreateEntry, 0)
	if err := json.Unmarshal([]byte(invlist), &list); err != nil {
		return err
	}
	if len(list) <= 0 {
		return errors.New("没有可入的订单")
	}
	for k,_ := range list {
		value := list[k]

		fmt.Println(value)

	}
	return nil
}
